﻿// CScrollingText.cs
// Author: Gant Briseno
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Casters.source.Managers;
#endregion

namespace Casters.source.Objects
{
    public class CScrollingText : CRenderObject
    {
        // Standard font for all scrolling text
        static SpriteFont m_Font = CGame.GetInstance().Content.Load<SpriteFont>("Fonts/arial");
        Vector2 m_Direction;
        string m_Text;
        float m_Velocity;
        float m_FadeTime;
        float m_Timer;

        /// <summary>
        /// Sets the default values for the text
        /// </summary>
        /// <param name="text">String to print</param>
        /// <param name="pos">Where to show it</param>
        public CScrollingText(string text, Vector2 pos)
            : base()
        {
            m_Text = text;
            m_vPosition = pos;
            m_ObjectType = TYPE.Text;
            m_Direction = new Vector2(0f, -1f);
            m_Velocity = 100f;
            m_FadeTime = 1.5f;
            m_Timer = 0f;
        }

        public override void LoadContent()
        {
        }

        public override void UnloadContent()
        {
        }

        /// <summary>
        /// Moves the text and progresses the timer
        /// </summary>
        /// <param name="dt">Elapsed Time</param>
        public override void Update(float dt)
        {
            m_Timer += dt;
            if (m_Timer >= m_FadeTime)
                m_bIsAlive = false;

            m_vPosition += (m_Direction * m_Velocity) * dt;

            base.Update(dt);
        }

        /// <summary>
        /// Draws the text to the screen with proper scale and alpha
        /// </summary>
        public override void Draw()
        {
            float zoom = CGame.GetInstance().m_Camera.m_fZoom;
            Vector2 temp = m_vPosition;
            temp.X -= 0.5f;
            temp.Y -= 0.5f;

            CRenderEngine.DrawString(m_Font, m_Text, m_vPosition * zoom, Color.Black * MathHelper.Lerp(m_FadeTime, 0f, m_Timer));
            CRenderEngine.DrawString(m_Font, m_Text, temp * zoom, Color.White * MathHelper.Lerp(m_FadeTime, 0f, m_Timer));
        }
    }
}
